package com.example.demo_mysql_mybatisplus;

import cn.hutool.core.date.DateUtil;
import com.example.demo_mysql_mybatisplus.util.DeployInfoUtil;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.util.LinkedHashMap;
import java.util.Map;

@SpringBootApplication(scanBasePackages = {
        "com.example.demo_mysql_mybatisplus.**"  ,
        "com.example.customized.${customized.code.package}.**" // 动态的 额外 扫描配置
})
@MapperScan(basePackages = {
        "com.example.demo_mysql_mybatisplus.**.daos.**",
        "com.example.customized.${customized.code.package}.**.daos.**" // 动态的 额外 扫描配置
})
//@EnableFeignClients(basePackages = "com.example.**")
@EnableCaching(proxyTargetClass = true)
@EnableScheduling
@EnableAsync(proxyTargetClass = true)
public class DemoMysqlMybatisplusApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(DemoMysqlMybatisplusApplication.class, args);

        System.out.println("启动成功。。。");

        DeployInfoUtil.get();

        showContextInfo( context );
    }




    static void showContextInfo(ConfigurableApplicationContext context) {

        System.out.println("--------------------------------------");

        Map<String,Object> map = new LinkedHashMap<>(25);
        map.put("sun.desktop",context.getEnvironment().getSystemProperties().get("sun.desktop"));
        map.put("os.name",context.getEnvironment().getSystemProperties().get("os.name"));
        map.put("os.version",context.getEnvironment().getSystemProperties().get("os.version"));
        map.put("user.name",context.getEnvironment().getSystemProperties().get("user.name"));
        map.put("user.language",context.getEnvironment().getSystemProperties().get("user.language"));
        map.put("user.country",context.getEnvironment().getSystemProperties().get("user.country"));
        map.put("user.timezone",context.getEnvironment().getSystemProperties().get("user.timezone"));
        map.put("user.home",context.getEnvironment().getSystemProperties().get("user.home"));
        map.put("user.dir",context.getEnvironment().getSystemProperties().get("user.dir"));
        map.put("file.encoding",context.getEnvironment().getSystemProperties().get("file.encoding"));
        map.put("java.home",context.getEnvironment().getSystemProperties().get("java.home"));
        map.put("file.encoding",context.getEnvironment().getSystemProperties().get("file.encoding"));
        map.put("java.home",context.getEnvironment().getSystemProperties().get("java.home"));
        map.put("sun.boot.library.path",context.getEnvironment().getSystemProperties().get("sun.boot.library.path"));
        map.put("java.version",context.getEnvironment().getSystemProperties().get("java.version"));
        map.put("java.runtime.version",context.getEnvironment().getSystemProperties().get("java.runtime.version"));
        map.put("java.vm.name",context.getEnvironment().getSystemProperties().get("java.vm.name"));
        map.put("java.vm.version",context.getEnvironment().getSystemProperties().get("java.vm.version"));

        map.put("context id",context.getId());
        map.put("context StartupDate", DateUtil.date(context.getStartupDate()).toString());
        map.put("PID",context.getEnvironment().getSystemProperties().get("PID"));
        map.put("local.server.port",context.getEnvironment().getPropertySources().get("server.ports").getProperty("local.server.port"));

        map.forEach((k,v)->{
            System.out.println(k+"---"+v);
        });

        System.out.println("--------------------------------------");
    }

}
